<template>
<Card>
  <p slot="title"><Icon type="md-search"></Icon>筛选搜索</p>
  <div slot="extra">
    <Button shape="circle" type="primary" icon="md-search" @click="onSearch">{{$t('search')}}</Button>
    <Button shape="circle" icon="md-sync" @click="onReset">{{$t('reset')}}</Button>
  </div>
  <Form ref="searchForm" :model="form" label-position="right" :label-width="100">
    <Row type="flex"><% table.columns.forEach(function(item){if(item.searchable){if(item.formtype=='text'){%>
      <Col>
      <FormItem label="<%=item.remark%>" prop="<%=item.javaProperty%>">
        <Input v-model="form.<%=item.javaProperty%>" placeholder=""></Input>
      </FormItem>
      </Col><%}else if(item.formtype=='textarea'){%>
      <Col>
      <FormItem label="<%=item.remark%>" prop="<%=item.javaProperty%>">
        <Input type="textarea" v-model="form.<%=item.javaProperty%>" placeholder=""></Input>
      </FormItem>
      </Col><%}else if(item.formtype=='radio'){%>
      <Col>
      <FormItem label="<%=item.remark%>" prop="<%=item.javaProperty%>">
        <RadioGroup v-model="form.<%=item.javaProperty%>"><% item.items.forEach(function(itemm){if(typeof(itemm.value)=='number'){%>
            <Radio :label="<%=itemm.value%>"><%=itemm.label%></Radio><%}else{%>
            <Radio label="<%=itemm.value%>"><%=itemm.label%></Radio><%}})%>
        </RadioGroup>
      </FormItem>
      </Col><%}else if(item.formtype=='select'){%>
      <Col>
      <FormItem label="<%=item.remark%>" prop="<%=item.javaProperty%>">
        <Select v-model="form.<%=item.javaProperty%>"><% item.items.forEach(function(itemm){if(typeof(itemm.value)=='number'){%>
            <Option :value="<%=itemm.value%>"><%=itemm.label%></Option><%}else{%>
            <Option value="<%=itemm.value%>"><%=itemm.label%></Option><%}})%>
        </Select>
      </FormItem>
      </Col><%}else if(item.formtype=='selectdict'){%>
      <Col>
      <FormItem label="<%=item.remark%>" prop="<%=item.javaProperty%>">
        <SelectDict v-model="form.<%=item.javaProperty%>" type="<%=item.type%>"></SelectDict>
      </FormItem>
      </Col><%}}})%>
    </Row>
  </Form>
</Card>
</template>
<script>
export default {
  props: {
    params: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {<% var list=table.columns.filter(item=>{return item.searchable})%>
      form: {<% list.forEach(function(item,index){if(item.formtype){%>
        <%=item.javaProperty%>: <%if(typeof(item.defaultValue)=='number'){%><%=item.defaultValue%><%}else{%>'<%=item.defaultValue%>'<%}%><%}if(index<list.length-1){%>,<%}})%>
      },<% var listRule=table.columns.filter(item=>{return item.formtype!='none'&&typeof(item.defaultValue)!='number'})%>
      rule: {<% listRule.forEach(function(item,index){if(item.formtype!='none'&&typeof(item.defaultValue)!='number'){%>
        <%=item.javaProperty%>: [
          { required: <%=item.required==true%>, message: '<%=item.remark%>不能为空', trigger: 'blur' }
        ]<%if(index<listRule.length-1){%>,<%}}})%>
      }
    }
  },
  mounted () {
    // this.form = this.model
  },
  methods: {
    onSearch () {
      this.$emit('on-search', this.form)
    },
    onReset () {
      this.$refs['searchForm'].resetFields()
    }
  }
}
</script>
